package test.view;

import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;

import test.presenter.DefaultCallback;
import test.presenter.DefaultPresenter;

import com.google.inject.Inject;

public class DefaultView extends JPanel implements DefaultPresenter.MyView {
	private static final long serialVersionUID = -31187623896194569L;
	private final DefaultCallback defaultCallback;
	private JLabel helloLabel;
	private JButton closeButton;

	@Inject
	public DefaultView(DefaultCallback defaultCallback) {
		this.defaultCallback = defaultCallback;
		initComponents();
	}

	public void initComponents() {
		helloLabel = new JLabel("Hello " + System.getProperty("user.name"));
		helloLabel.setBounds(10, 10, 100, 30);
		closeButton = new JButton("Close");
		closeButton.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				defaultCallback.onCloseButton();
			}
		});
		closeButton.setBounds(10, 50, 100, 30);

		add(helloLabel);
		add(closeButton);
	}

	@Override
	public void setHelloLabelText(String text) {
		helloLabel.setText(text);
	}

	@Override
	public Component asComponent() {
		return this;
	}

}
